package com.ruoyi.drone.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.drone.domain.DroneTask;
import com.ruoyi.drone.service.IDroneTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务发布管理Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/drone/taskManagement")
public class DroneTaskManagementController extends BaseController
{
    @Autowired
    private IDroneTaskService droneTaskService;

    /**
     * 查询任务发布列表
     */
    @PreAuthorize("@ss.hasPermi('drone:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DroneTask droneTask)
    {
        startPage();
        List<DroneTask> list = droneTaskService.selectDroneTaskList(droneTask);
        return getDataTable(list);
    }

    /**
     * 导出任务发布列表
     */
    @PreAuthorize("@ss.hasPermi('drone:task:export')")
    @Log(title = "任务发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DroneTask droneTask)
    {
        List<DroneTask> list = droneTaskService.selectDroneTaskList(droneTask);
        ExcelUtil<DroneTask> util = new ExcelUtil<DroneTask>(DroneTask.class);
        util.exportExcel(list, "任务发布数据");
    }

    /**
     * 获取任务发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('drone:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(droneTaskService.selectDroneTaskByTaskId(taskId));
    }

    /**
     * 新增任务发布
     */
    @PreAuthorize("@ss.hasPermi('drone:task:add')")
    @Log(title = "任务发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DroneTask droneTask)
    {
        return toAjax(droneTaskService.insertDroneTask(droneTask));
    }

    /**
     * 修改任务发布
     */
    @PreAuthorize("@ss.hasPermi('drone:task:edit')")
    @Log(title = "任务发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DroneTask droneTask)
    {
        return toAjax(droneTaskService.updateDroneTask(droneTask));
    }

    /**
     * 删除任务发布
     */
    @PreAuthorize("@ss.hasPermi('drone:task:remove')")
    @Log(title = "任务发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(droneTaskService.deleteDroneTaskByTaskIds(taskIds));
    }

    /**
     * 审核任务发布
     */
    @PreAuthorize("@ss.hasPermi('drone:task:audit')")
    @Log(title = "任务发布", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody DroneTask droneTask)
    {
        return toAjax(droneTaskService.updateDroneTask(droneTask));
    }

    /**
     * 更新任务状态
     */
    @PreAuthorize("@ss.hasPermi('drone:task:edit')")
    @Log(title = "任务发布", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public AjaxResult updateStatus(@RequestBody DroneTask droneTask)
    {
        return toAjax(droneTaskService.updateDroneTask(droneTask));
    }
}
